package xyz.syyrjx.registry.load;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import xyz.syyrjx.registry.SyyrjxRpcRegistryClass;
import xyz.syyrjx.registry.conf.SyyrjxRpcRegistryConfiguration;
import xyz.syyrjx.registry.constant.SyyrjxRpcProviderRegistryTable;
import xyz.syyrjx.registry.task.SyyrjxRpcRegistryMarkDeadPorviderSchedule;

/**
 * @author 大地崩坏苍蝇兽
 * @date 2023/1/12 - 16:09
 */
public class SyyrjxRpcRegistryServerLoadAware implements ApplicationContextAware {

    private static final Logger LOGGER = LoggerFactory.getLogger(SyyrjxRpcRegistryServerLoadAware.class);

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SyyrjxRpcRegistryMarkDeadPorviderSchedule schedule = new SyyrjxRpcRegistryMarkDeadPorviderSchedule();
        schedule.run();
        LOGGER.debug("定时死亡任务开启");
        LOGGER.debug("" + SyyrjxRpcRegistryConfiguration.getConfiguration());
        SyyrjxRpcProviderRegistryTable.setSecondsToDead(SyyrjxRpcRegistryConfiguration.getConfiguration().getMicroSecondsToDead());

        SyyrjxRpcRegistryClass registryLoad = applicationContext.getBean(SyyrjxRpcRegistryClass.class);
        registryLoad.serverStart();
    }
}
